package com.ybkj.daijia.serverUtils;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class UseAllDataUtil {

    /**
     * 查看客户完整电话号码
     *
     * @param phone
     * @return
     */
    public static String useAllData(String phone) {
        Subject subject = SecurityUtils.getSubject();

        boolean usealldata = false;
        if (subject.isPermitted("usealldata")) {
            usealldata = true;
        }
        if (StringUtils.isNotBlank(phone)) {
            if (!usealldata) {
                if (phone.length() > 6) {
                    String newPhone = phone.substring(3, 7);
                    newPhone = phone.replace(newPhone, "****");
                    phone = newPhone;
                }
            }
        }
        return phone;
    }

    /**
     * 查看司机完整电话号码
     *
     * @param phone
     * @return
     */
    public static String useAllDataDriver(String phone) {
        Subject subject = SecurityUtils.getSubject();

        boolean usealldataDriver = false;
        if (subject.isPermitted("usealldataDriver")) {
            usealldataDriver = true;
        }
        if (StringUtils.isNotBlank(phone)) {
            if (!usealldataDriver) {
                if (phone.length() > 6) {
                    String newPhone = phone.substring(3, 7);
                    newPhone = phone.replace(newPhone, "****");
                    phone = newPhone;
                }
            }
        }
        return phone;
    }
}
